<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>字典管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">


<form class="layui-form" action="">
	<div class="layui-form-item searchLine">
		<div class="layui-inline">
			<label class="layui-form-label">访问路径</label>
			<div class="layui-input-inline">
				<input type="text" placeholder="请输入访问路径" value="${path}" id="path" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">标题描述</label>
			<div class="layui-input-inline">
				<input type="text" placeholder="请输入标题描述" value="${sysTableVo.tableComment}" id="title" class="layui-input">
			</div>
		</div>
	</div>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>搜索框</legend>
	</fieldset>
	<#list sysUseColumnList as sysColumn>
		<div class="layui-form-item searchLine">
			<div class="layui-inline">
				<label class="layui-form-label">名称</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入名称" value="${sysColumn.columnComment}" class="layui-input name">
				</div>
				<label class="layui-form-label">name值</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入name值" value="${sysColumn.columnName}" class="layui-input keyword">
				</div>
				<label class="layui-form-label">开启搜索框</label>
				<div class="layui-input-inline">
					<select class="status" lay-filter="status">
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
				</div>
				<label class="layui-form-label hide1" style="display: none;">类型</label>
				<div class="layui-input-inline hide1"  style="display: none;">
					<select class="type" lay-filter="type">
						<option value="input">输入框</option>
						<option value="select">下拉框</option>
					</select>
				</div>
				<label class="layui-form-label hide2"  style="display: none;">下拉框字典码</label>
				<div class="layui-input-inline hide2"  style="display: none;">
					<input type="text" name="code" placeholder="请输入字典码" class="layui-input code">
				</div>
			</div>
		</div>
	</#list>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>展示列</legend>
	</fieldset>
	<#list sysColumnList as sysColumn>
		<div class="layui-form-item listLine">
			<div class="layui-inline">
				<label class="layui-form-label">名称</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入名称" value="${sysColumn.columnComment}" class="layui-input name">
				</div>
				<label class="layui-form-label">name值</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入name值" value="${sysColumn.columnName}" class="layui-input keyword">
				</div>
				<label class="layui-form-label">开启搜索框</label>
				<div class="layui-input-inline">
					<select class="status" lay-filter="status">
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
				</div>
				<label class="layui-form-label hide1" style="display: none;">类型</label>
				<div class="layui-input-inline hide1"  style="display: none;">
					<select class="type" lay-filter="type">
						<option value="input">输入框</option>
						<option value="select">下拉框</option>
						<option value="date">日期类型</option>
					</select>
				</div>
				<label class="layui-form-label hide2"  style="display: none;">下拉框字典码</label>
				<div class="layui-input-inline hide2"  style="display: none;">
					<input type="text" name="code" placeholder="请输入字典码" class="layui-input code">
				</div>
			</div>
		</div>
	</#list>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>
<div style="width: 100%">
	<textarea style="width: 100%; height: 300px;" id="showPage"></textarea>
</div>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">
    layui.use(['form','jquery','checkUtil','baseUtil'], function() {
        var form = layui.form,
            $ = layui.jquery,
            checkUtil = layui.checkUtil,
            baseUtil = layui.baseUtil;
        form.on('select(status)', function(data){
            if(data.value==1){
                $(data.elem).parent().parent().find(".hide1").show();
			}else{
                $(data.elem).parent().parent().find(".hide1").hide();
                $(data.elem).parent().parent().find(".hide2").hide();
			}
        });
        form.on('select(type)', function(data){
            if(data.value=="select"){
                $(data.elem).parent().parent().find(".hide2").show();
            }else{
                $(data.elem).parent().parent().find(".hide2").hide();
            }
        });
        //监听提交
        form.on('submit(submitBtn)', function(data){
            var showPage='<!DOCTYPE html><html><head><meta charset="utf-8"><title>'+$("#title").val()+'</title><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'+
                '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">'+
                '<meta name="apple-mobile-web-app-status-bar-style" content="black">'+
                '<meta name="apple-mobile-web-app-capable" content="yes">'+
                '<meta name="format-detection" content="telephone=no">'+
                '<link rel="stylesheet" href="$\{s.base}/js/layui/css/layui.css" media="all" />'+
                '<link rel="stylesheet" href="$\{s.base}/css/base/base.css" media="all" />'+
                '</head>'+
                '<body class="childrenBody">';
            showPage+=createTool();
            showPage+=createList();
            showPage+='</body></html>';
            $("#showPage").val(showPage);
            return false;
        });
		var codes="";
		var selectJson="";
        /**
         * 创建列表页
         * */
        function createList() {
            var searchContent="";
            $(".listLine").each(function (index,obj) {
                var name=$(obj).find(".name").val();
                var keyword=$(obj).find(".keyword").val();
                var status=$(obj).find(".status").val();
                var type=$(obj).find(".type").val();
                var code=$(obj).find(".code").val();
                if(status=="1"){
                    if(checkUtil.isEmpty(code)){
                        code="";
                    }
                    //开启
                    if(checkUtil.isNotEmpty(searchContent)){
                        searchContent+=',{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }else{
                        searchContent='{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }
                }
            });
            if(checkUtil.isNotEmpty(searchContent)){
                var path=$("#path").val();
                var listJson=JSON.parse('['+searchContent+']');
                return createListLine(listJson,path);
            }
            return "";
        }
        /**
         * js内容
         * */
        function createListLine(listJson,path) {
            var strSelect='<scriptTag type="text/html" id="entityBar">' +
				'<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit">编辑</a>' +
				'<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>'+
				'</scriptTag><scriptTag type="text/javascript" src="$/{s.base}/js/layui/layui.js"></scriptTag>'+
				'<scriptTag type="text/javascript" src="$/{s.base}/js/base/base.js"></scriptTag>';
            var cols="{type: 'checkbox', fixed: 'left'},{type: 'numbers', title: '序号'}";
            if(listJson!=null){
                listJson.forEach(function(e,i){
                    if(e.type=="select"){
                        if(checkUtil.isEmpty(codes)){
                            codes=e.code;
						}else{
                            if(!(codes.indexOf(e.code)>-1)){
                                codes+=","+e.code;
							}
						}
                        cols+=",{field: '"+e.id+"', title: '"+e.name+"',align:'center', templet:function(d){return pageUtil.aceeptDictContentName(dictData,'"+e.code+"',d."+e.id+");}}";
					}else if(e.type=="date"){
                        cols+=",{field: '"+e.id+"', title: '"+e.name+"',width:190, align:'center', templet:function(d){return dateUtil.formatDate(new Date(d."+e.id+"), \"yyyy-MM-dd hh:mm:ss\");}}";
                    }else{
                        cols+=",{field: '"+e.id+"', title: '"+e.name+"',align:'center'}";
                    }
                });
                cols+=",{title: '操作',width:150, templet:'#entityBar',align:\"center\",fixed: 'right'}";
            }
            strSelect+="<scriptTag type=\"text/javascript\">layui.use(['jquery','pageUtil','table','dateUtil'],function(){ var $ = layui.jquery,dateUtil = layui.dateUtil,table = layui.table,pageUtil = layui.pageUtil;";
            if(checkUtil.isEmpty(codes)){
				strSelect+="var url=\"/"+path+"/page\";"+
                    "var cols=["+cols+"];"+
                    "var tableIns = pageUtil.initDate(cols,url,true);";
            }else{
                strSelect+='var tableIns = null;pageUtil.initDict("'+codes+'",function (dictData) {';
                if(selectJson!=null){
                    selectJson.forEach(function(e,i){
                        if(e.type=="select"){
                            strSelect+='pageUtil.showDict($("#'+e.id+'"),pageUtil.aceeptDictContentList(dictData,"'+e.code+'"),"请选择'+e.name+'");';
                        }
                    });
                }
                strSelect+="var url=\"/"+path+"/page\";"+
                    "var cols=["+cols+"];"+
                    "tableIns = pageUtil.initDate(cols,url,true);});";
			}

            strSelect+='table.on(\'tool(entityList)\', function(obj){'+
            'var layEvent = obj.event,'+
                'data = obj.data;'+
            'if(layEvent === \'edit\'){'+
               ' pageUtil.editPopup("编辑","/'+path+'/getEntity?id="+data.id);'+
            '}else if(layEvent === \'del\'){'+
                'pageUtil.delete("确定删除该项吗？","/'+path+'/delete", {"id":data.id,"_method":"DELETE"},function (data) {'+
                    'tableIns.reload();'+
                '});'+
            '}'+
       ' });})<\/scriptTag>';

			return strSelect;
		}
        /**
		 * 创建工具栏
		 * */
        function createTool() {
            var searchContent="";
            $(".searchLine").each(function (index,obj) {
                var name=$(obj).find(".name").val();
                var keyword=$(obj).find(".keyword").val();
                var status=$(obj).find(".status").val();
                var type=$(obj).find(".type").val();
                var code=$(obj).find(".code").val();
                if(status=="1"){
                    if(checkUtil.isEmpty(code)){
                        code="";
                    }
                    //开启
                    if(checkUtil.isNotEmpty(searchContent)){
                        searchContent+=',{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }else{
                        searchContent='{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }
                }
            });
            if(checkUtil.isNotEmpty(searchContent)){
                var path=$("#path").val();
                selectJson=JSON.parse('['+searchContent+']');
                return createSeacher(selectJson,path);
            }
            return "";
        }

        /**
		 * 工具栏
		 * */
        function createSeacher(selectJson,path) {
            var strSelect="";
            if(selectJson!=null){
                strSelect+='<form class="layui-form"><blockquote class="layui-elem-quote quoteBox" id="tool"><div class="layui-inline">';
                selectJson.forEach(function(e,i){
                    strSelect+='<label class="layui-input-inline">'+e.name+'</label>';
                    strSelect+='<label class="layui-input-inline">'+contentController(e)+'</label>';
                });
                strSelect+='<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a></div>';
            }
            strSelect+='<div class="layui-inline"><a class="layui-btn layui-btn-normal addBtn" data-title="添加"  data-url="/'+path+'/getEntity">添加</a></div></blockquote><table id="entityList" lay-filter="entityList"></table></form>';
        	return strSelect;

        }



        /**
         **控件部分
         **/
		///////////////////////////////////////////////////////////////////////////////////
		// 描述：控制器-控制返回插件类型
		//开发人：虞胜强
		//开发时间：2018/6/19
		///////////////////////////////////////////////////////////////////////////////////
        function contentController(entity){
            var str="";
            if(entity.type=="select"){
                //下拉框
                if(checkUtil.isEmpty(codes)){
                    codes=entity.code;
                }else{
                    if(!(codes.indexOf(entity.code)>-1)){
                        codes+=","+entity.code;
                    }
                }
                str='<select name="'+entity.id+'" id="'+entity.id+'"></select>';
            }else if(entity.type=="input"){
                //输入框
                str='<input type="text" class="layui-input" name="'+entity.id+'" placeholder="请输入'+entity.name+'" />'
            }
            return str;
        }

    });
</script>
</body>
</html>